using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
using Service;
using Service.Main;
using ViewModel.Test;
using ViewModel.AlertCreate;
using ViewModel.Agriculture;
using System;
using ViewModel.MessageRelease;
using ViewModel.StationControl;
using ViewModel.PictureInfo;
using ViewModel.SystemManagement;
using ViewModel.StationManager;

namespace ViewModel
{
    public class ViewModelLocator
    {
        public ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
            if (ViewModelBase.IsInDesignModeStatic)
            {
                RegisterDesignService();
            }
            else
            {
                RegisterService();
            }

            RegisterDomainModel();
        }

        private void RegisterDomainModel()
        {
            SimpleIoc.Default.Register<MainViewModel>();
            SimpleIoc.Default.Register<LogOnViewModel>();
            SimpleIoc.Default.Register<UserManagerViewModel>();
            SimpleIoc.Default.Register<TestViewModel>();
            SimpleIoc.Default.Register<AlertMakeViewModel>();
            SimpleIoc.Default.Register<AlertRecordViewModel>();
            SimpleIoc.Default.Register<AlertRecordDetailViewModel>();
            SimpleIoc.Default.Register<AlertDocViewModel>();
            SimpleIoc.Default.Register<AlertDocEditViewModel>();
            SimpleIoc.Default.Register<PagerTestViewModel>();
            SimpleIoc.Default.Register<MessageRecordViewModel>();
            SimpleIoc.Default.Register<MessageReleaseViewModel>();
            SimpleIoc.Default.Register<StationControlViewModel>();
            SimpleIoc.Default.Register<ValveControlViewModel>();
            SimpleIoc.Default.Register<ValveControlRecordViewModel>();
            SimpleIoc.Default.Register<AreaWeatherPictureViewModel>();
            SimpleIoc.Default.Register<AgricultureViewModel>();
            SimpleIoc.Default.Register<UserInsertViewModel>();
            SimpleIoc.Default.Register<UserRoleManageViewModel>();
            SimpleIoc.Default.Register<StationSettingViewModel>();
            SimpleIoc.Default.Register<StationDetailViewModel>();
            SimpleIoc.Default.Register<StationSettingEditViewModel>();
            SimpleIoc.Default.Register<StationElementConfigViewModel>();
            SimpleIoc.Default.Register<StationUserMapViewModel>();
            SimpleIoc.Default.Register<StationUserMapSettingViewModel>();
            SimpleIoc.Default.Register<StationUserMapDetailViewModel>();
            SimpleIoc.Default.Register<StationElementViewModel>();
            SimpleIoc.Default.Register<StationElementEditViewModel>();            
        }

        private void RegisterDesignService()
        {
            SimpleIoc.Default.Register<IUserService, UserService_Design>();
            SimpleIoc.Default.Register<IRoleService, RoleService_Design>();
            SimpleIoc.Default.Register<IMainService, MainService_Design>();
            SimpleIoc.Default.Register<IAlertMakeService, AlertMakeService_Design>();
            SimpleIoc.Default.Register<IAlertRecordService, AlertRecordService_Design>();
            SimpleIoc.Default.Register<IAlertDocService, AlertDocService_Design>();

            SimpleIoc.Default.Register<IStationServcie, StationService_Design>();
            SimpleIoc.Default.Register<IElementService, ElementService_Design>();
            SimpleIoc.Default.Register<ITagInfoService, TagInfoService_Design>();

            SimpleIoc.Default.Register<IMessageInfoService, MessageInfoService_Design>();

            SimpleIoc.Default.Register<IAreaService, AreaServcie_Design>();
            SimpleIoc.Default.Register<IValveControlService, ValveControlService_Design>();
            SimpleIoc.Default.Register<IPictureInfoService, PictureInfoService_Design>();
            SimpleIoc.Default.Register<IAgricultureService, AgricultureService_Design>();
        }
        private void RegisterService()
        {
            SimpleIoc.Default.Register<IUserService, UserService>();
            SimpleIoc.Default.Register<IRoleService, RoleService>();
            SimpleIoc.Default.Register<IMainService, MainService>();
            SimpleIoc.Default.Register<IAlertMakeService, AlertMakeService>();

            SimpleIoc.Default.Register<IAlertRecordService, AlertRecordService>();
            SimpleIoc.Default.Register<IAlertDocService, AlertDocService>();

            SimpleIoc.Default.Register<IStationServcie,StationService>();
            SimpleIoc.Default.Register<IElementService, ElementService>();
            SimpleIoc.Default.Register<ITagInfoService, TagInfoService>();

            SimpleIoc.Default.Register<IMessageInfoService, MessageInfoService>();

            SimpleIoc.Default.Register<IAreaService, AreaService>();
            SimpleIoc.Default.Register<IValveControlService, ValveControlService>();
            SimpleIoc.Default.Register<IPictureInfoService, PictureInfoService>();
            SimpleIoc.Default.Register<IAgricultureService, AgricultureService>();
        }

        public MainViewModel MainViewModel => ServiceLocator.Current.GetInstance<MainViewModel>();
        public LogOnViewModel LogOnViewModel => ServiceLocator.Current.GetInstance<LogOnViewModel>();
        public UserManagerViewModel UserManagerViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<UserManagerViewModel>();

        public TestViewModel TestView => ServiceLocator.Current.GetInstance<TestViewModel>();
        
        public AlertMakeViewModel AlertMakeViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<AlertMakeViewModel>();

        public AlertRecordViewModel AlertRecordViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<AlertRecordViewModel>();
        public AlertRecordDetailViewModel AlertRecordDetailViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<AlertRecordDetailViewModel>();
        public AlertDocViewModel AlertDocViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<AlertDocViewModel>();

        public MessageRecordViewModel MessageRecordViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<MessageRecordViewModel>();
        public MessageReleaseViewModel MessageReleaseViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<MessageReleaseViewModel>();

        public StationControlViewModel StationControlViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<StationControlViewModel>();
        public ValveControlRecordViewModel ControlValueViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<ValveControlRecordViewModel>();

        public AreaWeatherPictureViewModel AreaWeatherPictureViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<AreaWeatherPictureViewModel>();

        public StationSettingViewModel StationSettingViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<StationSettingViewModel>();
        public StationUserMapViewModel StationUserMapViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<StationUserMapViewModel>();
        public StationElementViewModel StationElementViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<StationElementViewModel>();

        public PagerTestViewModel PagerTestViewModel => SimpleIoc.Default.GetInstanceWithoutCaching<PagerTestViewModel>();

        public AgricultureViewModel AgricultureViewModel => ServiceLocator.Current.GetInstance<AgricultureViewModel>();

        public static void Cleanup()
        {
            
        }
    }
}